﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace UdpPeer
{
    /// <summary>
    /// 值转换器
    /// </summary>
    public class EndPintValueConvert:System.Windows.Data.IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            string ep = value.ToString();

            return ep;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string epstr = value.ToString();
             System.Net.IPEndPoint ep;
            try
            {
                var arr = epstr.Split(':');
                ep = new IPEndPoint(IPAddress.Parse(arr[0]), int.Parse(arr[1]));
            }
            catch {
                ep = new IPEndPoint(IPAddress.IPv6Any, 0);
            }
            return ep;
        }
    }
}
